<script>
    export default {
        name: 'MusicList',
        data() {
            return {

            }
        },
        // props: ['list', 'isShow']
        props: {
            list: {
                type: Array,
                default: function () {
                    return []
                }
            },
            isShow: {
                type: Boolean,
                default: true
            }
        },
		methods: {
			// 跳转进入音乐播放界面，并且传送id
			playMusic(id, name) {
				this.$router.push({
					// path: '/songpage/' + id + name,
					name: 'Songpage',
					params: {id, name}
				});
			}
		}
    }
</script>

<template>
    <div>
        <div class="list" v-for="(item, index) in list" :key="item.id">
            <!-- 方法1：控制编号显示隐藏-->
            <!--<div class="code" v-if="isShow">{{ index + 1 }}</div>-->
            <!--热歌榜-->
            <!--<div class="code" v-else :class="{ 'code-red' : index < 3 }">{{ index > 8 ? index + 1 : '0' + (index + 1) }}</div>-->
            <!--方法2：使用插槽渲染歌曲编号序列-->
            <slot name="code" :index="index"></slot>
            <div class="list-item" @click="playMusic(item.id, item.name)">
                <div class="left">
                    <div class="subtitle">{{ item.name }} <span>{{ item.alia[0] }}</span></div>
                    <div class="author">
                        <span v-for="ele in item.ar" :key="ele.id" class="ele">
                            {{ ele.name }}
                        </span>
                        - {{ item.al.name }}
                    </div>
                </div>
                <div class="right">
                    <img src="@/assets/images/play.png">
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="less">
    .list {
        display: flex;

        .code {
            width: 1rem;
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
        }

        .code-red {
            color: #df3436;
        }

        .list-item {
            border-bottom: 1px solid #eeeeee;
            padding-left: 10px;
            padding-top: 6px;
            padding-bottom: 6px;
            display: flex;
            flex: 1;

            .left {
                flex: 1;
                width: 5.5rem;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                word-break: normal;

                .subtitle {
                    font-size: 17px;
                    overflow: hidden;
                    color: #333333;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    word-break: normal;

                    span {
                        //font-size: 12px;
                        color: #888888;
                    }
                }

                .author {
                    margin-top: 4px;
                    font-size: 12px;
                    color: #888888;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    word-break: normal;

                    .ele {
                        &::after {
                            content: '/';
                        }
                    }

                    .ele:last-child {
                        &::after {
                            content: '';
                        }
                    }
                }
            }

            .right {
                width: 0.9rem;

                img {
                    width: 20px;
                    margin-top: 10px;
                }
            }
        }
    }
</style>